{% extends "base.html" %}

{% block title %}Задание{% endblock %}

{% block content %}
<form action="{{ id }}" method="post" autocomplete="off">
    <input type="hidden" name="mode" value="{% block exercise_mode %}{% endblock %}">
  {% block exercise_body %}
  {% endblock %}
  <br>
  <input type="submit" value="Дальше" id="submit">
  <p>Нажмите = для ввода макрона.</p>
</form> 
<script>
answer = document.getElementById('answer0');
submit = document.getElementById('submit');
if (answer) {
    answer.focus();
} else if (submit) {
    submit.focus();
}


var macrons = [["a", "ā"],
    ["o", "ō"],
    ["e", "ē"],
    ["i", "ī"],
    ["u", "ū"],
    ["y", "ȳ"]];

var dead_macron = "=";

function add_macrons (input) {
    var old_cursor = input.selectionStart;
    var old_value = input.value;
    var new_value = old_value;
    for (var i = 0; i < macrons.length; ++i) {
        new_value = new_value.replace(macrons[i][0] + dead_macron, macrons[i][1]);
    }
    var delta = old_value.length - new_value.length;
    input.value = new_value;
    input.selectionStart = old_cursor - delta;
    input.selectionEnd = old_cursor - delta;
}

</script>
{% endblock %}
